from django.db import models
from django.utils.html import format_html
GENDER_CHOICES =(
    (1,"男"),
    (2,"女")
)

# Create your models here.
#uuid存储用户的openid
class WeChatUser(models.Model):

    uuid = models.CharField(max_length=32, verbose_name='用户唯一识别码',null=True)
    username = models.CharField(max_length=32, verbose_name='用户昵称',null=True)
    gender = models.CharField(verbose_name='性别', choices=GENDER_CHOICES,max_length=6)
    city = models.CharField(max_length=32, verbose_name='城市',null=True)
    province = models.CharField(max_length=32, verbose_name='省份',null=True)
    image = models.CharField(max_length=500,verbose_name="头像",null=True)
    desc = models.CharField(max_length=32, verbose_name='简介', null=True)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)
    id_delete = models.BooleanField(default=False,verbose_name="黑名单")
    is_level = models.BooleanField(default=False,verbose_name="管理员")

    class Meta:
        verbose_name = '用户信息表'
        verbose_name_plural = verbose_name

    def show_image(self):
        return format_html(
            '<a target="_blank" href="{}"> <img width="42" height="42"  src="{}"/></a>', self.image,self.image)
    show_image.short_description = '头像'

    def __str__(self):
        return self.username
